package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.promotion.seckill.dos.SeckillApplyDO;
import com.enation.app.javashop.model.promotion.tool.dos.PromotionGoodsDO;
import com.enation.app.javashop.service.promotion.groupbuy.GroupbuyScriptManager;
import com.enation.app.javashop.service.promotion.seckill.SeckillScriptManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author fk
 * @version v2.0
 * @Description: 促销脚本客户端
 * @date 2020/4/16
 * @since v7.2.0
 */
@RestController
@RequestMapping("/client/promotion/{promotion_id}/script")
@ApiIgnore
public class PromotionScriptClientController {

    @Autowired
    private GroupbuyScriptManager groupbuyScriptManager;

    @Autowired
    private SeckillScriptManager seckillScriptManager;

    @RequestMapping(value = "/group-buy", method = RequestMethod.POST)
    public void createGroupBuyCacheScript(@PathVariable("promotion_id") Long promotionId, @RequestBody List<PromotionGoodsDO> goodsList) {
        groupbuyScriptManager.createCacheScript(promotionId, goodsList);
    }

    @RequestMapping(value = "/group-buy", method = RequestMethod.DELETE)
    public void deleteGroupBuyCacheScript(@PathVariable("promotion_id") Long promotionId,@RequestBody List<PromotionGoodsDO> goodsList) {
        groupbuyScriptManager.deleteCacheScript(promotionId, goodsList);
    }

    @RequestMapping(value = "/seckill", method = RequestMethod.DELETE)
    public void deleteCacheScript(@PathVariable("promotion_id") Long promotionId,@RequestBody List<SeckillApplyDO> goodsList) {
        seckillScriptManager.deleteCacheScript(promotionId, goodsList);
    }
}
